package com.investment.advisor.repository;

import com.investment.advisor.entity.StrategyFactor;
import com.investment.advisor.entity.Strategy;
import com.investment.advisor.entity.Factor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StrategyFactorRepository extends JpaRepository<StrategyFactor, Long> {
    List<StrategyFactor> findByStrategy(Strategy strategy);
    
    List<StrategyFactor> findByFactor(Factor factor);
    
    StrategyFactor findByStrategyAndFactor(Strategy strategy, Factor factor);
    
    @Modifying
    @Query("DELETE FROM StrategyFactor sf WHERE sf.strategy.id = :strategyId")
    void deleteByStrategyId(@Param("strategyId") Long strategyId);
    
    @Modifying
    @Query("DELETE FROM StrategyFactor sf WHERE sf.strategy.id = :strategyId AND sf.factor.id = :factorId")
    void deleteByStrategyIdAndFactorId(@Param("strategyId") Long strategyId, @Param("factorId") Long factorId);
} 